/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simfinal;

//import com.jme.math.Vector3f;

/**
 *
 * @author jkeister
 */
public class Rocket extends Particle
{
	
	Vector propel = null;
	//Vector rotation = null;
	double rotation = 0.0;
	double degree = 0.0;
	double x = 0;
	double y = 0;
	
	String firingSequence;
	
	char LE = 'e';
	char RE = 'e';
	boolean empty = false;
	int fullTank = 0;
	int fuelConsumed = 0;
	
	/** Creates a new instance of Rocket */
    /*
    public Rocket()
    {
	   position = new Vector();
	   rotation = new Vector(0,0,0);
    }
	
    public Rocket(Vector v)
    {
	   position = v;
	   rotation = new Vector(0,0,0);
    }*/
	
	public Rocket(String fs, Vector v)
	{
		super();
		super.mass = 0;
		super.x0.set(v);
		super.x0dot.set(0, 0, 0);
		
		firingSequence = fs;
		fullTank = firingSequence.length();
		propel = null;
		//rotation = new Vector(0,0,0);
	}
	
	public boolean Fire()
	{
		//advance on string
		if(firingSequence != null)
		{
			if(fuelConsumed < fullTank-1)
			{
				LE = firingSequence.charAt(fuelConsumed++);
				RE = firingSequence.charAt(fuelConsumed++);
				
				//degree = rotation % 360;
				
				//if(degree < 0)
					//degree = 360+degree;
				
				if(LE=='1' && RE=='1')
				{
					//accelerate 2x
					propel = new Vector(2*Math.sin(degree),2*Math.cos(degree),0);
					//System.out.println("Fire both!");	
				}
				else
				{
					if(LE=='0' && RE=='0')
					{
						//System.out.println("Drift");
                                                propel = new Vector(0,0,0);
					}
					else
					{
						if(LE=='1')
						{
							//accelerate and rotate right
                                                        propel = new Vector(Math.sin(degree),Math.cos(degree),0);
							degree = degree + 0.174;
						}
						else
						{
                                                   	//accelerate and rotate left
                                                        propel = new Vector(Math.sin(degree),Math.cos(degree),0);
							degree = degree - 0.174;
						}
					}
				}
			}
			else
				empty = true;
		}
		else
			empty = true;
		
		if(isEmpty());
			//System.out.println("EMPTY!");
                else
                {
                    propel.mult(.035f);	
                    super.x0dot.add(propel);
                }
                
		return isEmpty();
	}

	public boolean isEmpty()
	{
		return empty;
	}
        
        public float getRotation()
        {
            return new Float(degree).floatValue();
        }
}